package cc.telecomdigital.tdstock.activity.groups.monitor.util;

import java.io.ByteArrayInputStream;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import cc.telecomdigital.tdstock.Framework.UniqueItem.TDStockLog;
import cc.telecomdigital.tdstock.activity.groups.more.push.util.XMLHelper;

/**
 * 
 * Project：tdstock3
 * Package：cc.telecomdigital.tdstock.activity.groups.monitor.util
 * Class：ReadBookMark Description： Creater：hunter
 * [chengpanggang@126.com//hunter@mango.cc] CreateTime：Date：Nov 2, 2011
 * Time：2:53:11 PM Modifier ：hunter [chengpanggang@126.com//hunter@mango.cc]
 * Modify time： Date：Nov 2, 2011 Time：2:53:11 PM Modify Remarks： read Book Mark
 * 
 * @version
 * 
 */
public class ReadStatus
{
	private static final String	TAG	= ReadStatus.class.getSimpleName();
	private static ReadStatus	rbm;

	public static ReadStatus getInstance()
	{
		if (rbm == null)
		{
			rbm = new ReadStatus();
		}
		return rbm;
	}

	private ReadStatus()
	{
	}

	public String getStatus(String inPutString)
	{
		// String inPutString = DataRead.InputStreamConvertToString(in);
		TDStockLog.d(TAG, (inPutString == null ? "" : inPutString));
		if (null == inPutString || "".equals(inPutString))
		{
			return null;
		}
		else if (inPutString.indexOf("Bookmark") == -1)
		{
			return null;
		}
		else
		{
			TDStockLog.d(TAG, inPutString);
			Document dom = XMLHelper.parseURL(new ByteArrayInputStream(
					inPutString.getBytes()));
			if (dom == null)
			{
				return null;
			}
			else
			{
				Element root = dom.getDocumentElement();
				String temp = "status";
				NodeList lists = root.getElementsByTagName("Status");
				temp = ((Element) lists.item(0)).getFirstChild()
						.getNodeValue();
				// temp=root.getElementsByTagName("Status").item(0).getNodeValue();
				return temp;
			}
		}
	}
	// /**
	// * get node tostring of nodetype
	// * @param node
	// * @return
	// */
	// public static String getNodeValue(Node node){
	// String str="";
	// NodeList temp=node.getChildNodes();
	// for (int i = 0; i < temp.getLength(); i++) {
	// if(temp.item(i).getNodeType()==Node.TEXT_NODE){
	// str=temp.item(i).toString().replace("#text:", "").replace("[",
	// "").replace("]", "").trim();
	// }
	// }
	// return str;
	// }
}
